using System;
using Microsoft.WindowsAzure;

namespace AzureContrib.WindowsAzure.StorageClient
{
	internal class CloudStorageAccountWrapper : ICloudStorageAccount
	{
		private readonly CloudStorageAccount cloudStorageAccount;

		public static implicit operator CloudStorageAccount(CloudStorageAccountWrapper cloudStorageAccountWrapper)
		{
			var wrappedCredentials =
				((StorageCredentialsWrapper)cloudStorageAccountWrapper.Credentials).WrappedCredentials;

			return new CloudStorageAccount(wrappedCredentials, cloudStorageAccountWrapper.BlobEndpoint,
																		 cloudStorageAccountWrapper.QueueEndpoint, cloudStorageAccountWrapper.TableEndpoint);
		}

		public static CloudStorageAccountWrapper FromICloudStorageAccount(ICloudStorageAccount cloudStorageAccount)
		{
			return cloudStorageAccount as CloudStorageAccountWrapper;
		}

		internal CloudStorageAccountWrapper(CloudStorageAccount cloudStorageAccount)
		{
			this.cloudStorageAccount = cloudStorageAccount;
		}

		public Uri BlobEndpoint
		{
			get { return cloudStorageAccount.BlobEndpoint; }
		}

		public Uri QueueEndpoint
		{
			get { return cloudStorageAccount.QueueEndpoint; }
		}

		public Uri TableEndpoint
		{
			get { return cloudStorageAccount.TableEndpoint; }
		}

		public IStorageCredentials Credentials
		{
			get { return cloudStorageAccount.Credentials.Wrap(); }
		}

		public override string ToString()
		{
			return cloudStorageAccount.ToString();
		}

		public string ToString(bool exportSecrets)
		{
			return cloudStorageAccount.ToString();
		}
	}
}